
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.Managers;
using Tathata.Common.Utils;

namespace Tathata.Web.Administration
{
    public partial class Administration_ProductTemplateDetails : BaseNopAdministrationPage
    {
        private void BindData()
        {
            ProductTemplate productTemplate = ProductTemplateManager.GetByProductTemplateID(this.ProductTemplateID);
            if (productTemplate != null)
            {
                this.txtName.Text = productTemplate.Name;
                this.txtTemplatePath.Text = productTemplate.TemplatePath;
                this.txtDisplayOrder.Value = productTemplate.DisplayOrder;
                this.lblCreatedOn.Text = productTemplate.CreatedOn.ToString();
                this.lblUpdatedOn.Text = productTemplate.UpdatedOn.ToString();
            }
            else
                Response.Redirect("ProductTemplates.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.BindData();
            }
        }

        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    ProductTemplate productTemplate = ProductTemplateManager.GetByProductTemplateID(this.ProductTemplateID);

                    if (productTemplate != null)
                    {
                        productTemplate = ProductTemplateManager.UpdateProductTemplate(productTemplate.ProductTemplateID, txtName.Text,
                            txtTemplatePath.Text, txtDisplayOrder.Value, productTemplate.CreatedOn, DateTime.Now);
                        Response.Redirect("ProductTemplateDetails.aspx?ProductTemplateID=" + productTemplate.ProductTemplateID.ToString());
                    }
                    else
                        Response.Redirect("ProductTemplates.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                ProductTemplateManager.DeleteProductTemplate(this.ProductTemplateID);
                Response.Redirect("ProductTemplates.aspx");
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }

        public int ProductTemplateID
        {
            get
            {
                return CommonHelper.QueryStringInt("ProductTemplateID");
            }
        }
    }
}
